
var offer_dialog=function(the_target_id,the_id,img,user_id,user_name,top){
	$('#'+the_id).append('<div class="dialog"></div><div class="my_dialog" style="top:'+(top-250)+'px;"></div><div class="my_dialog" style="top:'+(top)+'px;"></div>');
	$('#'+the_id+' div.my_dialog:eq(0)').append('<h4>目标详情</h4><i class="fa fa-times"></i><div class="target_dialog" style="padding: 0.5em 1em 2em 0.5em;;background:white"></div>');
//$('#'+the_id+'  div.my_dialog:eq(0)').append('<button class="make_sure" style="margin-right:2.5em"> 加入</button>');
	$('#'+the_id+' div.my_dialog:eq(1)').append( '<h4>目标分享</h4><i class="fa fa-times"></i><div style="padding:0.5em 1em;background:white">'+
             '<textarea  name="target_describe"></textarea>'+
             '<button class="target_share">分享到广场</button><img class="the_user" src="'+img+'"/><h4 >智行校园</h4><span >我的目标分享</span>'+
            ' <textarea   disabled="disabled" name="target_describe"></textarea>'+
            '<div class="share_dialog" style="background:#eeeeee;margin: 0 1.5em;padding-bottom:1em"><h3></h3><p style="height:1em"></p>'+
            '<span id="toggle_article" >展开全文</span><h3 class="table-toggle" style="margin-top:0;margin-bottom:0">展开分解任务<i class="fa fa-caret-right fa-lg" ></i> </h3><div>'+
            '<table id="dialog_table_share"></table></div></div></div>');
	/*var detail_colums = [[ "target_id","target_describe", "target_sign","target_source","sign" ],
			              [ "序号", "描述", "签到次数", "相关资料" ,"今日签到"] ];*/
    var detail_share = [[ "c_id","c_name", "total","c_resource" ],
		              [ "序号", "描述", "签到次数", "相关资料" ] ];
    $('#'+the_id+' div.my_dialog:eq(1) textarea:eq(0)').val('#晒我的目标#每天完成一个小目标，虽然微小，但千里之行，始于足下.终有一天我会实现我的大目标#智行校园之我的目标# https://mb.yunhua.com/ebill/index.html');
    $('#'+the_id+' div.my_dialog:eq(1) textarea:eq(1)').val('#晒我的目标#每天完成一个小目标，虽然微小，但千里之行，始于足下.终有一天我会实现我的大目标#智行校园之我的目标# https://mb.yunhua.com/ebill/index.html');
   
    var the_url='/WDDXSERVER/professionalAssessment/getTargetDetailsFromEvaluating';
	 $.ajax({
		 url:the_url,
		 data:{targetID:the_target_id,userid:user_id,ticket:ticket},
		 type:'post'
	 }).done(function(data){
		 data = data.content.message;
		 var img='';
		 $('#'+the_id+'  div.my_dialog:eq(0) div.target_dialog').append('<h3>'+data.t_name+'</h3><button class="make_sure" style="margin-right:2.5em"> 加入</button><button><i class="fa fa-share-alt"></i>分享到广场</button>');
		 $('#'+the_id+'  div.my_dialog:eq(0) div.target_dialog').append('<p style="height:1em"><font size="3" >描述：</font>'+data.t_describe+'</p><span id="toggle_article" >展开全文</span>');
		 if(data.sign_count!='0'){
			 for(var i=0;i<data.sign_img.length;i++)
				  img+='<img src="'+data.sign_img[i]+'"/>';
			  if(data.sign_img.length<9)
				  $('#'+the_id+'  div.my_dialog:eq(0) div.target_dialog').append('<p style="margin:0"><font size="3" >今日签到：</font>'+img+'</p>');
			  else
			      $('#'+the_id+'  div.my_dialog:eq(0) div.target_dialog').append('<p style="margin:0"><font size="3" >今日签到：</font>'+img+'...共'+data.sign_count+'人</p>');
		 }
		 $('#'+the_id+'  div.my_dialog:eq(0) div.target_dialog').append('<font size="3" style="width:100%;margin-left:1.5em;display:block">目标分解：</font><div style="margin:0.2em 1.5em;width:calc(100% - 3em);"><table id="dialog_table"></table></div>');
		 $('div#'+the_id).show('slow');
		 var the_colum= detail_share;
					table("dialog_table",data.details,the_colum, false,150);
					$('div.my_dialog span#toggle_article').click(function(){
						$(this).text()=='展开全文'? $(this).text('收起').prev().css('height','auto')
								:$(this).text('展开全文').prev().css('height','1em');
					});
					$('button.make_sure').unbind('click').click(function(){
	    		        $.ajax({
		    		    	   url:'/WDDXSERVER/target/addTarget',
		    		    	   data:{userid:user_id,targetID:the_target_id,ticket:ticket},
		    		    	   type:'post',
		    		    	   success:function(){
		    		    		   win.alert("系统提示","目标已添加成功！");
		    		    		   $('div#'+the_id).hide('fast');
		    		    		   $('div.body-panel p.btns button:eq("0")').unbind('click').click(function(){
			    	    				 win.close();
			    	    			 });
			    	    		    setTimeout("$('div.win').css('display','none')",3000);	
		    		    	   }
		    		       });
						$('div#'+the_id).empty();
					});
					$('#'+the_id+' div.my_dialog:eq(0) button:contains(分享到广场)').click(function(){
						  $('#'+the_id+' div.my_dialog:eq(1) div.share_dialog h3:eq(0)').text(data.t_name);
						  $('#'+the_id+' div.my_dialog:eq(1) div.share_dialog p').html('<font size="3" >描述：</font>'+data.t_describe);
						  table("dialog_table_share",data.details,detail_share, false,250);
						  $('#'+the_id+' div.my_dialog:eq(1)').toggle();
						  $('#'+the_id+' div.my_dialog:eq(1) i.fa-caret-right').unbind('click').click(function(){
							  $('#'+the_id+' div.my_dialog:eq(1) h3.table-toggle').next().toggle();
						  });
						  $('#'+the_id+' div.my_dialog:eq(1) i.fa-times').unbind('click').click(function(e){
							  $('div#'+the_id+' div.my_dialog:eq(1)').hide('fast');
							  e.stopPropagation();
						  });
						  $('#'+the_id+' div.my_dialog:eq(1) button.target_share').unbind('click').click(function(e){
							  $.ajax({
			    		    	   url:'/WDDXSERVER/target/shareTarget',
			    		    	   data:{targetID:the_target_id,userid:user_id,username:encodeURI((user_name)),Devicename:' ',content:encodeURI($(this).prev().val()),ticket:ticket},
			    		    	   type:'post',
			    		    	   success:function(){
			    		    		   $('#'+the_id+' div.my_dialog:eq(1)').hide('fast');
			    		    		   win.alert("系统提示","分享成功！");
			    		    	   }
			    		       });
							  e.stopPropagation();
						  });
						  $('#'+the_id+' div.my_dialog:eq(1) textarea:eq(0)').bind('focus',function(){
							  $(this).val('');
							  $('#'+the_id+' div.my_dialog:eq(1) textarea:eq(0)').bind('input propertychange', function() {
								  $('#'+the_id+' div.my_dialog:eq(1) textarea:eq(1)').val($(this).val());
							  });
						  })
					});
					$('div.my_dialog:eq(0) i.fa-times').click(function(){
						$('div#'+the_id).hide('fast');
						$('div#'+the_id).empty();
					});
					
	 });
	 dialog_move($('#'+the_id+' div.my_dialog:eq(0)'));
	    dialog_move($('#'+the_id+' div.my_dialog:eq(1)'));
};
function dialog_move(object){
	object.hover(function(){
		$(this).css('cursor','move');
	},function(){
		$(this).css('cursor','default');
	});
	object.mousedown(
	            function(event){
	    	//	$(this).css('cursor','move');
	                var isMove = true;
	                var screenW =$(document).width(); 
	                var screenH = $(document).height();
	                var dialogW=object.outerWidth(true);
	                var dialogH=object.outerHeight(true);
	                var abs_x = event.pageX - object.offset().left; 
	                var abs_y = event.pageY - object.offset().top;
	    			
	                $(document).mousemove(function (event) {  
	                        if (isMove) {  
	                            var obj = object; 
	                            var left_x = event.pageX - abs_x;
	                            var top_y = event.pageY - abs_y;
	    					//	console.log(top_y);
	                            if((screenW-dialogW)<=left_x){
	                                left_x = screenW-dialogW;
	                            }
	                            if((screenH-dialogH)<=top_y){
	                                top_y = screenH-dialogH;
	                            }
	                            if(left_x<0){
	                                left_x=20;
	                            }
	                            if(top_y<0){
	                                top_y=10;
	                            }
	    						
	                            obj.css({'left':left_x, 'top':top_y});  
	                        }  
	                    }
	                 ).mouseup(  
	                                function () {  
	                                	
	                                       isMove = false;  
	                                    }  
	                                );
	            }
	        );
};
function table(id, data,colums, pagination,height) {
	var colum = [];
	for (var i = 0; i < colums[0].length; i++){
		 if(i==0)
		       colum[i]={field:colums[0][i],title:colums[1][i],valign:"middle",align:"center",formatter:actionFormatter_text};
		 else
    		   colum[i]={field:colums[0][i],title:colums[1][i],valign:"middle",align:"center"};
		 }
	$('#' + id).bootstrapTable({
		columns : colum,
		height:height,
		data : data,
		pagination : pagination,
		search : false,
		searchOnEnterKey : true,
		locale : 'zh-CN'
	});		
};
function actionFormatter_text(value, row, index) {
	   return ['第'+(index+1)+'项'].join('');
	};

